import 'package:fate_blind_box/theme/theme_color.dart';
import 'package:fate_blind_box/ui/Home/activity/act_details_page.dart';
import 'package:fate_blind_box/ui/cooperation/activity/group_promote/group_promote_list.dart';
import 'package:fate_blind_box/utils/common_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../../../../utils/confirm_alert.dart';
import '../../../Home/activity/act_list_model.dart';

class MyActItemView extends StatelessWidget {
  FuturePopular? dataModel;
  String tabTitle = '';
  Function? delAction;

  MyActItemView({this.dataModel, this.tabTitle = '', this.delAction, Key? key})
      : super(key: key);

  double leftMargin = 14.w;
  double leftPadding = 15.w;
  double imgWidth = 114.w;
  double imgHeight = 69.w;

  @override
  Widget build(BuildContext context) {
    dataModel ??= FuturePopular();
    double rightMaxMargin =
        1.sw - leftMargin * 2 - leftPadding - leftPadding - 10 - imgWidth;
    return Container(
      margin: EdgeInsets.only(top: 13, left: leftMargin, right: leftMargin),
      decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(5), color: Colors.white),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          GestureDetector(
            onTap: () {
              Get.to(ActDetailsPage(
                dataModel: dataModel,
                actId: dataModel?.activityId,
              ));
            },
            child: Container(
              color: Colors.white,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  const SizedBox(
                    height: 13,
                  ),
                  Padding(
                    padding: EdgeInsets.only(
                      left: leftPadding,
                    ),
                    child: Text(
                      '创建日期 ${dataModel?.actiCreateTIme ?? ''}',
                      style: const TextStyle(
                          color: Color(
                            0xFFA7A7A7,
                          ),
                          fontSize: 12),
                    ),
                  ),
                  const SizedBox(
                    height: 6,
                  ),
                  Container(
                    height: 0.5,
                    color: ThemeColor.lineColor,
                  ),
                  const SizedBox(
                    height: 14,
                  ),
                  Padding(
                    padding: EdgeInsets.only(left: leftPadding),
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        AppWidget.commonEmptyImg(
                            url: dataModel?.actiCover,
                            imgHeight: imgHeight,
                            imgWidth: imgWidth,
                            radius: 5),
                        SizedBox(
                          width: leftMargin,
                        ),
                        SizedBox(
                          height: imgHeight,
                          width: rightMaxMargin,
                          child: Column(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Expanded(
                                child: Text(
                                  dataModel?.actiTitle ?? '',
                                  maxLines: 2,
                                  style: TextStyle(
                                    color: ThemeColor.black3D3D3DColor,
                                    fontSize: 16,
                                    overflow: TextOverflow.ellipsis,
                                  ),
                                ),
                              ),
                              Row(
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                children: [
                                  Text(
                                    dataModel?.actiCost ?? '免费',
                                    style: const TextStyle(
                                        color: Color(0XFFE84D46),
                                        fontSize: 16,
                                        fontWeight: FontWeight.w500),
                                  ),
                                  Container(
                                    padding: const EdgeInsets.symmetric(
                                        horizontal: 3, vertical: 1),
                                    decoration: BoxDecoration(
                                        borderRadius: BorderRadius.circular(5),
                                        border: Border.all(
                                            color: ThemeColor.appColor,
                                            width: 1)),
                                    child: Text(
                                      '我要报名',
                                      style: TextStyle(
                                          color: ThemeColor.appColor,
                                          fontSize: 12),
                                    ),
                                  ),
                                ],
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                  const SizedBox(
                    height: 14,
                  ),
                ],
              ),
            ),
          ),
          Container(
            height: 0.5,
            color: ThemeColor.lineColor,
          ),
          const SizedBox(
            height: 8,
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.end,
            children: [
              Visibility(
                visible: isShowPromoteBtn(),
                child: getCornerBtnView(
                    title: '首页推广',
                    titleColor: ThemeColor.black3D3D3DColor,
                    delBtn: () {
                      ConfirmAlertDialog.showAlertView(context);
                    }),
              ),
              Visibility(
                visible: isShowShareBtn(),
                child: const SizedBox(
                  width: 20,
                ),
              ),
              Visibility(
                visible: isShowShareBtn(),
                child: getCornerBtnView(
                    title: '分享',
                    titleColor: ThemeColor.black3D3D3DColor,
                    space: 14,
                    delBtn: () {
                      Get.to(GroupPromoteListPage(
                        itemModel: dataModel,
                      ));
                    }),
              ),
              Visibility(
                visible: iHiddenDelBtn(),
                child: const SizedBox(
                  width: 20,
                ),
              ),
              Visibility(
                visible: iHiddenDelBtn(),
                child: getCornerBtnView(
                    title: '删除',
                    titleColor: ThemeColor.redE84D46Color,
                    space: 14,
                    delBtn: () {
                      ConfirmAlertDialog.showView(context, rightAction: () {
                        if (delAction != null) {
                          delAction!(dataModel);
                        }
                      });
                    }),
              ),
              const SizedBox(
                width: 13,
              ),
            ],
          ),
          const SizedBox(
            height: 8,
          ),
        ],
      ),
    );
  }

  bool iHiddenDelBtn() {
    if (tabTitle.contains('发起')) {
      return true;
    }
    if (tabTitle.contains('参与')) {
      return false;
    }
    if (tabTitle.contains('过期')) {
      int isPost = dataModel?.isPost ?? 0;
      bool isTure = isPost == 1 ? true : false;
      return isTure;
    }
    return false;
  }

  //是否显示首页推广
  bool isShowPromoteBtn() {
    if (tabTitle.contains('发起')) {
      int isMatchMaker = dataModel?.isMatchmaker ?? 0;
      bool isTrue = isMatchMaker == 1 ? true : false;
      return isTrue;
    }
    if (tabTitle.contains('参与')) {
      return false;
    }
    if (tabTitle.contains('过期')) {
      return false;
    }
    return false;
  }

  //是否显示首页分享
  bool isShowShareBtn() {
    if (tabTitle.contains('参与')) {
      return false;
    }if (tabTitle.contains('发起')) {
      return true;
    }else{
      int isMatchMaker = dataModel?.isPost ?? 0;
      bool isTrue = isMatchMaker == 1 ? true : false;
      return isTrue;
    }
  }

  Widget getCornerBtnView(
      {String title = '', Color? titleColor, double? space, Function? delBtn}) {
    return GestureDetector(
      onTap: () {
        if (delBtn != null) {
          delBtn();
        }
      },
      child: Container(
        padding: EdgeInsets.symmetric(vertical: 4, horizontal: space ?? 9),
        decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(17),
            boxShadow: const [
              BoxShadow(
                  blurRadius: 4,
                  color: Color.fromRGBO(0, 0, 0, 0.1),
                  offset: Offset(0, 1))
            ]),
        alignment: Alignment.center,
        child: Text(
          title,
          style: TextStyle(color: titleColor, fontSize: 16),
        ),
      ),
    );
  }
}
